package com.treetao.union.db.service.impl;

import com.treetao.union.db.model.MallPSku;
import com.treetao.union.db.model.MallTopicSku;
import com.treetao.union.db.mapper.MallTopicSkuMapper;
import com.treetao.union.db.service.MallPSkuService;
import com.treetao.union.db.service.MallTopicSkuService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * <p>
 * 专题关联商品 服务实现类
 * </p>
 *
 * @author Dev.M
 * @since 2020-04-15
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class MallTopicSkuServiceImpl extends ServiceImpl<MallTopicSkuMapper, MallTopicSku> implements MallTopicSkuService {
	@Autowired
	private MallPSkuService mallPSkuService;

	@Override
	public List<MallPSku> getSkus(Long topicId) {
		QueryWrapper<MallTopicSku> q = new QueryWrapper<MallTopicSku>();
		q.eq("topic_id", topicId);
		List<MallTopicSku> tSkus = list(q);
		if(tSkus!=null) {
			Object[] skudIds = tSkus.stream().map(item -> item.getSkuId()).toArray();
			if(skudIds==null || skudIds.length==0) {
				return null;
			}
			QueryWrapper<MallPSku> queryWrapper = new QueryWrapper<MallPSku>();
			queryWrapper.in("id", skudIds);
			return mallPSkuService.list(queryWrapper);
		}
		return null;
	}
	
}
